Skip to content

perf(state): measure contextual verification phases - #782

Open
evan-forbes wants to merge 3 commits into
mainfrom
perf/contextual-phase-metrics
Open

perf(state): measure contextual verification phases#782
evan-forbes wants to merge 3 commits into
mainfrom
perf/contextual-phase-metrics

Conversation

@evan-forbes

@evan-forbes evan-forbes commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • measure the full contextual interval, initial checks, parent-chain work, new
    chain construction, and state-writer snapshot cloning;
  • separate the cumulative UTXO snapshot from transparent spend checks;
  • measure shielded anchors, contextual block construction, and the parallel
    state update;
  • separate the parallel chain clone from Chain::push;
  • measure header-transition preparation and commit on success and error paths;
  • emit matching mined-only series for every phase on the mined-block path.

Motivation

The preserved memo-enabled field run reduced the median transaction phase to
1.795 ms. Its median state commit remained 34.338 ms. PR #781 separates writer
queue delay from writer execution. This PR splits writer execution so the fleet
can identify the next material optimization without inferring phase costs from
aggregate quantiles.

Safety

The change adds elapsed-time capture and histograms only. It does not move a
check, change state ownership, or alter chain selection.

The outer parallel_update duration includes task scheduling and completion.
The parallel_task.* durations overlap because block commitment, Sprout anchor
validation, and chain update run concurrently. Only parallel_update measures
their critical-path wall time.

Benchmark scope

This PR adds observability. It does not claim a runtime speedup. A synthetic
microbenchmark would not show whether these histograms partition the production
contextual interval. The state tests exercise every instrumented success and
error path. The next fleet run must compare each mined-only phase count with
the outer contextual count, then rank phase means from matching campaign
deltas. Concurrent parallel_task.* means must not be added together.

Verification

  • cargo test -p zakura-consensus -p zakura-state --lib --locked
    • 234 consensus tests passed and 1 test remained ignored
    • 567 state tests passed and 4 tests remained ignored
  • cargo clippy -p zakura-state -p zakura-consensus --all-targets -- -D warnings
  • cargo check -p zakura-state -p zakura-consensus --all-targets --locked
  • cargo fmt --all -- --check
  • npm exec --yes markdownlint-cli -- docs/changelog/unreleased/782.md --config .github/.markdownlint.yaml
  • git diff --check
  • ./scripts/changelog.py check

This PR adds docs/changelog/unreleased/782.md with an internal-only marker.

Stack

@evan-forbes
evan-forbes force-pushed the perf/contextual-profile-milestone branch from baf893d to 0a60c5b Compare August 23, 2026 04:43
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from da49f60 to a66e320 Compare August 23, 2026 04:43
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from a66e320 to ce7eaf6 Compare August 23, 2026 05:53
@evan-forbes
evan-forbes force-pushed the perf/contextual-profile-milestone branch from f9a5cea to e0904a8 Compare August 23, 2026 08:11
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from ce7eaf6 to 91c7ce2 Compare August 23, 2026 08:11
@evan-forbes
evan-forbes force-pushed the perf/contextual-profile-milestone branch from e0904a8 to cb86ca8 Compare August 23, 2026 16:46
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from 91c7ce2 to 8a61e72 Compare August 23, 2026 16:46
@evan-forbes
evan-forbes marked this pull request as ready for review August 23, 2026 17:25
@evan-forbes
evan-forbes force-pushed the perf/contextual-profile-milestone branch from cb86ca8 to da87178 Compare August 23, 2026 17:45
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch 3 times, most recently from 7de3197 to d555395 Compare August 23, 2026 18:52
@evan-forbes
evan-forbes force-pushed the perf/contextual-profile-milestone branch 2 times, most recently from b8b1f4c to bdf35bb Compare August 23, 2026 19:38
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from d555395 to abc601b Compare August 23, 2026 19:38
@evan-forbes
evan-forbes changed the base branch from perf/contextual-profile-milestone to main September 4, 2026 17:18
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from fc47ef7 to d71d7ea Compare September 4, 2026 18:03
@evan-forbes
evan-forbes changed the base branch from main to perf/contextual-profile-milestone September 4, 2026 18:04
"state.contextual.mined.transparent_spend.duration_seconds",
transparent_spend_start.elapsed(),
);
let spent_utxos = spent_utxos?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copied unspent outputs now stay in memory for the rest of validation, so we use more memory than before. We could free that copy as soon as the spending checks finish, like the old code did.

Base automatically changed from perf/contextual-profile-milestone to feat/optimistic-mined-block-inventory September 7, 2026 18:41
Base automatically changed from feat/optimistic-mined-block-inventory to main September 8, 2026 15:46
@evan-forbes evan-forbes added observability Metrics, health endpoints, and tracing perf labels Sep 10, 2026
@ValarDragon
ValarDragon force-pushed the perf/contextual-phase-metrics branch from d71d7ea to 1da7d1c Compare September 11, 2026 12:21
@ValarDragon
ValarDragon requested a review from a team September 11, 2026 12:21
// Reads from disk
//
// TODO: if these disk reads show up in profiles, run them in parallel, using std::thread::spawn()
let unspent_utxo_snapshot_start = Instant::now();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im worried about Instant::now() being called repeatedly being an atomic slowdown for small operations. (IIRC its around 30ns)

Its probably fine here though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

observability Metrics, health endpoints, and tracing perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants